import os
import hashlib
def execCmd(cmd):
    # print("执行:"+cmd)
    r = os.popen(cmd)
    text = r.read()
    r.close()
    text=text.strip()
    return text
def writeFile(fileName,content):
    with open(fileName,"w",encoding="utf-8") as file:
        file.write(content)
    file.close
def readFile(fileName):
    content=""
    with open(fileName,"r",encoding="utf-8",errors="ignore") as file:
        content=file.read()
    file.close
    return content
def getMd5(s):
    md = hashlib.md5()
    md.update(s.encode('utf-8'))
    return md.hexdigest()
def httpStatus(url):
    return execCmd("curl -Is -m 1 -w %{http_code} -o /dev/null '"+url+"'")
def getPomMd5(pomPath):
    #判断是否存在src目录
    content=readFile(pomPath)
    srcPath=pomPath.replace("pom.xml","src")
    if os.path.exists(srcPath):
        #获取所有文件
        for root, dirs, files in os.walk(srcPath):
            for file in files:
                content=content+readFile(os.path.join(root, file))
    return getMd5(content)

def getHealthStatus(url):
    return execCmd("curl -s -XGET '"+url+"' |jq -r '.status'")
def getCheckHealthStatus(url):
    return execCmd("curl -s -XGET '"+url+"' |jq -r '.data'")